package controller

import (
	"strings"

	"backEnd/common"
	"backEnd/model"
	"backEnd/util"

	"github.com/gin-gonic/gin"
)

func ShowAuthentications(ctx *gin.Context) { // 展示待审核认证记录
	var (
		DB      = common.GetDB()
		records []model.VerificationUser
	)

	if err := DB.Model(&model.VerificationUser{}).Where("status = ?", 0).Find(&records).Error; err != nil {
		ctx.JSON(500, gin.H{
			"msg": "查询记录失败",
			"err": err.Error(),
		})
		return
	}

	ctx.JSON(200, gin.H{"user": records})
}

func VerificationUserId(ctx *gin.Context) { // 修改用户审核状态与信息

}

func ShowAuditProducts(ctx *gin.Context) { //展示待审核商品记录
	var (
		DB        = common.GetDB()
		records   []model.ReportRecord
		reasons   []string
		reasonStr string
	)

	if err := DB.Where("status = ?", 0).First(&records).Error; err != nil {
		ctx.JSON(500, gin.H{
			"msg": "查询记录失败",
			"err": err.Error(),
		})
		return
	}

	// 将所有的举报原因拼接成一个字符串，以逗号分隔
	for i, record := range records {
		reasons = util.FromJSON(record.ReportReasons)
		reasonStr = strings.Join(reasons, ",")
		records[i].ReportReasons = reasonStr
	}

	ctx.JSON(200, gin.H{"records": records})
}

func AuditProduct(ctx *gin.Context) { // 修改商品审核状态与信息

}
